package cn.edu.ujn.park.service;

import cn.edu.ujn.park.dao.ParkingSpace;
import cn.edu.ujn.park.dao.ParkingSpaceMapper;
import cn.edu.ujn.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ParkingSpaceImpl implements IParkingSpace{

    @Autowired
    ParkingSpaceMapper spaceMapper;
    @Override
    public int deleteByPrimaryKey(Integer spaceId) {
        return spaceMapper.deleteByPrimaryKey(spaceId);
    }

    @Override
    public int insert(ParkingSpace row) {
        return spaceMapper.insert(row);
    }

    @Override
    public int insertSelective(ParkingSpace row) {
        return spaceMapper.insertSelective(row);
    }

    @Override
    public ParkingSpace selectByPrimaryKey(Integer spaceId) {
        return spaceMapper.selectByPrimaryKey(spaceId);
    }

    @Override
    public int updateByPrimaryKeySelective(ParkingSpace row) {
        return spaceMapper.updateByPrimaryKeySelective(row);
    }

    @Override
    public int updateByPrimaryKey(ParkingSpace row) {
        return spaceMapper.updateByPrimaryKey(row);
    }

    @Override
    public Page<ParkingSpace> selectAll(ParkingSpace space) {
        Page<ParkingSpace> page = new Page<>();
        List<ParkingSpace> list = spaceMapper.selectAll(space);
        Integer count = spaceMapper.selectCount();
        page.setRows(list);
        page.setPage(space.getStart());
        page.setTotal(count);
        page.setSize(space.getRows());
        return page;
    }

    @Override
    public Integer selectCount() {
        return spaceMapper.selectCount();
    }

    @Override
    public Page<ParkingSpace> selectByNumber(String spaceNumber) {
        Page<ParkingSpace> page = new Page<>();
        List<ParkingSpace> list = spaceMapper.selectByNumber(spaceNumber);
        Integer count = spaceMapper.selectCount();
        page.setRows(list);
        page.setPage(0);
        page.setTotal(count);
        page.setSize(10);
        return page;
    }

    @Override
    public List<ParkingSpace> selectAvailable() {
        return spaceMapper.selectAvailable();
    }

}
